package net.xdclass.xdclass.exception;


import net.xdclass.xdclass.utils.JsonData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public JsonData handle(Exception e){

        if (e instanceof XDException){
           XDException exception =  (XDException)e;
           return JsonData.buildError(exception.getCode(),exception.getMsg());
        }else {
            return JsonData.buildError("系统为止异常");
        }
    }
}
